package com.asa.controller;

import com.asa.bean.User;
import com.asa.common.utils.Com;
import com.asa.common.utils.ComUtils;
import com.asa.dao.UserRepositroy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2016/12/17.
 */

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserRepositroy userRepositroy;
    @Resource
    Com com;


    /**
     *
     * 查询全部用户
     * @return
     */
    @GetMapping("")
    public List<User> list(){
        com.write(userRepositroy.findAll());
        return null;
//        return userRepositroy.findAll();
    }

    /**
     * 添加一个用户
     * @return
     */
    @PostMapping("")
    public User add(User user){
        return userRepositroy.save(user);
    }

    /**
     * 根据id获取用户
     * @return
     */
    @GetMapping("/{id}")
    public User get(@PathVariable Integer id){
        return userRepositroy.findOne(id);
    }

    /**
     * 更新用户
     * @return
     */
    @PutMapping("/{id}")
    public User update(User user){
        return userRepositroy.save(user);
    }

    /**
     * 删除用户
     * @return
     */
    @DeleteMapping("/{id}")
    public void del(Integer id){
        userRepositroy.delete(id);
    }
}
